/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-03-03
 * Time: 13:36
 */
class Food {

}

class Fruit extends Food {

}

class Apple extends Fruit {

}

class Banana extends Fruit {

}

class Plate<T> {
    private T message;

    public T getMessage() {
        return message;
    }

    public void setMessage(T message) {
        this.message = message;
    }
}

public class Test1 {

    public static void main(String[] args) {
        Plate<Fruit> fruitPlate = new Plate<>();
        fruitPlate.setMessage(new Fruit());
        func1(fruitPlate);

        Plate<Food> foodPlate = new Plate<>();
        foodPlate.setMessage(new Food());
        func1(foodPlate);
    }

    public static void func1(Plate<? super Fruit> tmp) {
        System.out.println(tmp.getMessage());//无法确定接收
        //通配符的下界 可以添加 有子类 一般写入 可修改无法获取
        tmp.setMessage(new Apple());//可以添加
    }


    public static void main1(String[] args) {
        Plate<Apple> applePlate = new Plate<>();
        applePlate.setMessage(new Apple());
        func(applePlate);

        Plate<Banana> bananaPlate = new Plate<>();
        bananaPlate.setMessage(new Banana());
        func(bananaPlate);
    }

    public static void func(Plate<? extends Fruit> tmp) {
        //一般读取 可获取无法修改
        System.out.println(tmp.getMessage());
    }
}

